﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Ebada.Components;
using Ebada.Server;

namespace Itop.GpsCar.Web {
    public class Global : System.Web.HttpApplication {
        public static Castle.Windsor.IWindsorContainer IOC;
        private static IBaseSqlMapDao sqlMapper;

        public static IBaseSqlMapDao SqlMapper {
            get {
                if (sqlMapper == null)
                    sqlMapper = IOC.GetService<IBaseSqlMapDao>();

                return Global.sqlMapper;

            }
        }
        public static T GetService<T>() {
            return IOC.GetService<T>();
        }
        protected void Application_Start(object sender, EventArgs e) {
            if (IOC == null) {
                new ServerContainer();
                IOC = ServerContainer.PlatformServer;
            }
            log4net.Config.XmlConfigurator.Configure();
            //   在应用程序启动时运行的代码 
            //SiteMap.SiteMapResolve +=
            //        new SiteMapResolveEventHandler(AppendQueryString);
        }

       protected SiteMapNode AppendQueryString(object sender, SiteMapResolveEventArgs e)
        {
            if (e.Provider.CurrentNode != null)
            {
                SiteMapNode node = e.Provider.CurrentNode.Clone(true);
                Uri uri = new Uri(e.Context.Request.Url.ToString());
                node.Url += uri.Query;
                string title = e.Context.Request.QueryString.Get("pathtitle ");

                if (!string.IsNullOrEmpty(title))
                {
                    node.Title = Server.HtmlEncode(title);
                }

                return node;
            }
            else
            {
                return null;
            }
        } 

        protected void Session_Start(object sender, EventArgs e) {

        }

        protected void Application_BeginRequest(object sender, EventArgs e) {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e) {

        }

        protected void Application_Error(object sender, EventArgs e) {

        }

        protected void Session_End(object sender, EventArgs e) {

        }

        protected void Application_End(object sender, EventArgs e) {

        }
    }
}